package com.sardine.base.hbase.session.defaults;

import com.sardine.base.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.client.Connection;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 上海京东到家元信信息技术有限公司<br>
 * Created with IntelliJ IDEA.
 * Date:2017/11/21
 * Time:13:38
 *
 * @author daifeng<br>
 *         daifeng@imdada.cn
 * @since JDK 1.7 <br>
 * Copyright (c) 2017 imdada System Incorporated All Rights Reserved.
 */
public class HBaseConnectionManager {
    private static final Logger logger = LoggerFactory.getLogger(HBaseConnectionManager.class);

    private HBaseConfiguration configuration;
    private Connection connection;

    public HBaseConnectionManager(HBaseConfiguration configuration) {
        this.configuration = configuration;
    }


    public Connection getConnection() {
        if (connection == null) {
            synchronized (this) {
                if (connection == null) {
                    connection = configuration.getDataSource().getConnection();
                }
            }
        }
        return connection;
    }

}
